<?php
$ROOT = "../../../";
require_once ($ROOT . 'config/config.php');

class ResourcesTypeIndex{	
	private $db;
	private $post;
	private $smarty;
	
	function __construct($db, $post, $smarty){
		$this -> db 	= $db;
		$this -> post 	= $post;
		$this -> smarty = $smarty;
	}
	
	
	function insert(){
		$description = $this -> post['description'];
		if($description != "" && $description != " "){
			$resources_type = new ResourcesType('',$description);
		
			$result = $resources_type -> insert($this -> db,$resources_type);
		}
		echo $result;
	}
	
	function update(){
		$id			 = $this -> post['id'];
		$description = $this -> post['description'];
		
		if($description != "" && $description != " "){
			$resources_type = new ResourcesType($id,$description);
		
			$result = $resources_type -> update($this -> db,$resources_type);
		}
		echo $result;
	}
	
	function delete(){
		$id		= $this -> post['id'];
		$resources_type = new ResourcesType($id	,"");
		
		$result =  $resources_type -> delete($this -> db,$resources_type);
		echo $result;
	}
	
	
	function display(){		
		$result = ResourcesType::getList($this -> db);

		$this -> smarty ->assign('listResources' , $result);		
		$this -> smarty ->display('../templates/resources_type/index.tpl');
	}
	
	function main($db,$smarty,$post){
		$method = $post['method'];
		$index = new ResourcesTypeIndex($db,$post,$smarty);
		
		switch ($method){
			case 'insert':
				$index -> insert();		
				break;
			case 'update':
				$index -> update();		
				break;
			case 'delete':
				$index -> delete();		
				break;
			
			default:
				$index -> display();
		}
	}
}

ResourcesTypeIndex::main($db,$smarty,$_POST);

?>